import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from Driver.Driver import Blogdriver
class BlogDetail:
    driver=''
    url=''
    alert=''
    def __init__(self):
        self.driver=Blogdriver.driver
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=32966"



    # 节省编写时间的函数
    def Qtest(self, key):
            self.driver.find_element(By.CSS_SELECTOR, key)
    # 不登陆进入博客详情页
    def NoLongIn(self):
        self.driver.get(self.url)
    # 登陆后进入界面
    def LogIn(self):
        self.driver.get(self.url)
    # 博客详情页
    def BlogDetailScreen(self):
        # 检测各种元素存在
        self.Qtest("body > div.container > div.right > div > div.title")
        self.Qtest("body > div.container > div.right > div > div.date")
        self.Qtest("body > div.container > div.right > div > div.date")
        # 自己的博客会多出删除和编辑按钮
        if self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3").text=="zhangsan":
            self.Qtest("body > div.container > div.right > div > div.operating > button:nth-child(1)")
            self.Qtest("body > div.container > div.right > div > div.operating > button:nth-child(2)")
    #自己账号下存在编辑和删除功能
    # 删除博客
    def Delete(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)").click()
        self.alert=WebDriverWait(self.driver,2).until(expected_conditions.alert_is_present())
        self.alert.accept()
        Blogdriver.getscreen()
    # 编辑博客
    def Create(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(1)").click()
        Blogdriver.getscreen()


    #博客详情页界面博客列表
    # 点击主页
    def titlebarHome(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)").click()
        Blogdriver.getscreen()


    # 点击编辑页
    def titlebarCreate(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)").click()
        Blogdriver.getscreen()


    # 点击注销
    def titlebarOut(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        Blogdriver.getscreen()